# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Zerial <fernando@zerial.org>

pkgname=unrealircd
pkgver=6.0.7
pkgrel=1
pkgdesc="Open Source IRC Server"
arch=('loong64' 'x86_64')
url="https://www.unrealircd.org"
license=('GPL2')
depends=('openssl' 'curl' 'c-ares' 'tre' 'pcre2' 'libnsl' 'argon2')
conflicts=('ircd')
provides=('ircd')
backup=('etc/unrealircd/unrealircd.conf')
install=unrealircd.install
validpgpkeys=('1D2D2B03A0B68ED11D68A24BA7A21B0A108FF4A9')
source=(https://www.unrealircd.org/unrealircd4/unrealircd-$pkgver.tar.gz{,.asc}
	unrealircd.service
	unrealircd.tmpfiles.d
	unrealircd.sysusers.d
	install.pl
	source-date-epoch.patch)
sha256sums=('fc43081009012b2d7ec61f1a3dd14a6a180750ffb4605e8aec15f38de5fa8979'
            'SKIP'
            '5bb6016c379e6f040d8c625e3339c096ff66c4450aa024ca5b13ad3dec47c38e'
            '91b5e1d623b51ffd4734d73e35cead09be596460c41b9440406f92c9e2b4b9b1'
            '9e595176e63b301476982b1456d6ed065c479ff913b6743417ab8a9efdda0e3a'
            '43f07093ada8eb5c954f9e2e189610575906c690c0953fec041d4f2d31210d85'
            '1b9b3d5560f6633d4f31a521bc0ae17094d3afa28e703b4790eaefedcc9a92a8')

prepare() {
  cd unrealircd-$pkgver
  sed -i \
    -e 's|$(INSTALL) -m 0700|$(INSTALL) -m 0755|g' \
    -e 's|$(INSTALL) -m 0600|$(INSTALL) -m 0644|g' \
    Makefile.in
#  patch -p1 < ../source-date-epoch.patch
}

build() {
  cd unrealircd-$pkgver
  ./configure \
    --with-pidfile=/run/unrealircd/ircd.pid \
    --with-showlistmodes \
    --enable-ssl=/usr \
    --with-bindir=/usr/bin \
    --with-datadir=/var/lib/unrealircd \
    --with-controlfile=/run/unrealircd/unrealircd.ctl \
    --with-confdir=/etc/unrealircd \
    --with-modulesdir=/usr/lib/unrealircd \
    --with-logdir=/var/log/unrealircd \
    --with-cachedir=/var/cache/unrealircd \
    --with-docdir=/usr/share/doc/unrealircd \
    --with-tmpdir=/tmp \
    --with-scriptdir=/usr \
    --with-nick-history=2000 \
    --with-sendq=3000000 \
    --with-permissions=0644 \
    --with-fd-setsize=1024 \
    --enable-dynamic-linking
  make
}

package() {
  cd unrealircd-$pkgver

  export pkgdir
#  make INSTALL="$srcdir"/install.pl install DESTDIR="$pkgdir"
  make install DESTDIR="$pkgdir"
  mv "$pkgdir"/usr/unrealircd "$pkgdir"/etc/unrealircd/unrealircd
  cp "$pkgdir"/etc/unrealircd/examples/example.conf "$pkgdir"/etc/unrealircd/unrealircd.conf
  rm -rf "$pkgdir"/tmp

  install -Dm0644 "$srcdir"/unrealircd.service "$pkgdir"/usr/lib/systemd/system/unrealircd.service
  install -Dm0644 "$srcdir"/unrealircd.tmpfiles.d "$pkgdir"/usr/lib/tmpfiles.d/unrealircd.conf
  install -Dm0644 "$srcdir"/unrealircd.sysusers.d "$pkgdir"/usr/lib/sysusers.d/unrealircd.conf
}
